package root.electronclass.electronclass.personal.dialog

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.recyclerview.widget.LinearLayoutManager
import root.electronclass.electronclass.common.base.BasicAdapter
import root.electronclass.electronclass.common.base.BasicDialogFragment
import root.electronclass.electronclass.App
import root.electronclass.electronclass.databinding.ItemCharacterDetailsDialogBinding
import root.electronclass.electronclass.databinding.MessageDialogBinding
import root.electronclass.electronclass.other.PictureActivity
import root.electronclass.electronclass.mvp.entity.Message
import root.electronclass.electronclass.mvp.entity.PicDto


/**
 *
 * @author Lokiy
 * @date 2023/2/18 21:10
 */
class MessageDialog : BasicDialogFragment<MessageDialogBinding>() {

    override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
        binding.update(arguments?.getParcelable(DATA) ?: return)
    }

    companion object {
        const val DATA = "_DATA"
    }

}

fun MessageDialogBinding.update(it: Message) {
    Log.i("SchoolStudyDownDialog", "update: $it")
    title.text = it.mesageTitle
    content.text = it.messageContent
    recycler.layoutManager = LinearLayoutManager(App.app,LinearLayoutManager.HORIZONTAL,false)
    recycler.adapter  = adapter
    adapter.notifyChanged(it.picsUrlFormat)
}


private val adapter = BasicAdapter<PicDto, ItemCharacterDetailsDialogBinding> { holder, item ->
    holder.binding.pic.setImageURI(item.url)
    holder.binding.pic.setOnClickListener {
        val lists = ArrayList<String>()
        for (i in list){
            lists.add(i.url.orEmpty())
        }
        PictureActivity.startActivity(App.app, lists,0)
    }
}



